using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace XMTAEditor
{
	public partial class EnumComboBox : ComboBox
	{
		public EnumComboBox()
		{
			InitializeComponent();
			base.DropDownStyle = ComboBoxStyle.DropDownList;
		}

		bool ShouldSerializeDropDownStyle()
		{
			return base.DropDownStyle != ComboBoxStyle.DropDownList;
		}

		private Type enumType;
		private const string ND = "<Not defined>";

		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public Type EnumType
		{
			get { return enumType; }
			set
			{
				if (value != enumType)
				{
					base.Items.Clear();
					enumType = value;
					base.Items.Add(ND);
					foreach (string val in Enum.GetNames(enumType))
					{
						base.Items.Add(val);
					}
				}
			}
		}

		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public string EnumVal
		{
			get { if (base.SelectedIndex == 0) return null; return base.Text; }
			set
			{
				if (string.IsNullOrEmpty(value) || value == ND) { base.SelectedIndex = 0; return; }
				if (Enum.IsDefined(enumType, value)) { base.Text = value.ToString(); }
			}
		}
	}
}
